package indi.wshape1.takeawaydeliveryinfo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import indi.wshape1.takeawaydeliveryinfo.mapper.TakeoutInfoMapper;
import indi.wshape1.takeawaydeliveryinfo.pojo.TakeoutInfo;
import indi.wshape1.takeawaydeliveryinfo.service.TakeoutInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Wshape1
 * @description 针对表【t_takeout_info】的数据库操作Service实现
 * @since 2023-01-17 17:42:10
 */
@Service
public class TakeoutInfoServiceImpl extends ServiceImpl<TakeoutInfoMapper, TakeoutInfo>
        implements TakeoutInfoService {

    @Autowired
    @SuppressWarnings("all")
    private TakeoutInfoMapper takeoutInfoMapper;

    @Override
    public List<TakeoutInfo> getListByNameAndKeyword(String blockName, String groupName, String keyword) {

        QueryWrapper<TakeoutInfo> queryWrapper = new QueryWrapper<>();
        queryWrapper.and((q) ->
                q.like("user_name", keyword).or()
                        .like("phone", keyword).or()
                        .like("status", keyword).or()
                        .like("group_name", keyword).or()
                        .like("block_name", keyword).or()
                        .like("sender_phone", keyword).or()
                        .like("detail", keyword));


        if (blockName != null && groupName == null) {
            queryWrapper.and((q) -> q.eq("block_name", blockName));
        } else if (blockName != null) {
            queryWrapper.and((q) ->
                    q.eq("block_name", blockName)
                            .eq("group_name", groupName));
        }

        return list(queryWrapper);
    }

    @Override
    public int toggleStatusBatch(List<Integer> ids) {
        return takeoutInfoMapper.updateStatusBatch(ids);
    }

    @Override
    public int removeBatchByGroupIds(List<Integer> ids) {
        return takeoutInfoMapper.deleteBatchByGroupIds(ids);
    }

    @Override
    public int removeBatchByBlockIds(List<Integer> ids) {
        return takeoutInfoMapper.deleteBatchByBlockIds(ids);
    }


}